package yunquan.wang.modules.base.service.impl;

import java.util.Set;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import yunquan.wang.base.dao.springdata.BaseRepository;
import yunquan.wang.base.service.impl.BaseServiceImpl;
import yunquan.wang.modules.base.dao.UserBasicDao;
import yunquan.wang.modules.base.entity.Rolesinfo;
import yunquan.wang.modules.base.entity.UserBasic;
import yunquan.wang.modules.base.service.UserBasicService;

/**
 * UserBasic Service层 实现
 * 
 * @author 王云权 wangyunquan@gmail.com 用生成器 生成于 2011-09-30 22:37
 * 
 */
@Service("userBasicService")
@Transactional(value="jpaTransaction")
public class UserBasicServiceImpl extends BaseServiceImpl<UserBasic> implements
		UserBasicService {
	private UserBasicDao userBasicDao;


	@Resource
	public void setDao(UserBasicDao userBasicDao) {
		this.userBasicDao = userBasicDao;
	}

	public BaseRepository<UserBasic, String> getDao() {
		return userBasicDao;
	}

	@Override
	public UserBasic save(UserBasic entity, String[] rolesIds) {
	Set<Rolesinfo> rolesinfo=	entity.getRolesinfos();
	rolesinfo.clear();
	Rolesinfo role;
  for(String roleId:rolesIds)
  {
	  role=new Rolesinfo();
	  role.setId(roleId);
	  rolesinfo.add(role);
  }
  entity.setRolesinfos(rolesinfo);
		entity = save(entity);
		return entity;
	}

	@Override
	public UserBasic findByLoginName(String username) {
		return userBasicDao.findByLoginName(username);
	}

}
